#include<bits/stdc++.h>
using namespace std;

int a[105][105], b[105][105], c[105][105];

signed main() {
    int ra, rb, ca, cb;

    cin >> ra >> ca;
    for(int i = 1; i <= ra; i++)
        for(int j = 1; j <= ca; j++)
            cin >> a[i][j];

    cin >> rb >> cb;
    for(int i = 1; i <= rb; i++)
        for(int j = 1; j <= cb; j++)
            cin >> b[i][j];

    if(ca != rb)
        cout << "Error: " << ca << " != " << rb;
    else {
        cout << ra << " " << cb << "\n";
        for(int i = 1; i <= ra; i++) {
            for(int j = 1; j <= cb; j++) {
                for(int k = 1; k <= ca; k++) {
                    c[i][j] += a[i][k] * b[k][j];
                }
                if (j == 1)
                    cout << c[i][j];
                else
                    cout <<  " " << c[i][j];
            }
            cout << "\n";
        }
    }

    return 0;
}

